<?php

class Core_Component_Account_Controller_Backend_Password {
    
    function changeAction(){
        $GLOBALS[RC]->getHelper()->setLocation('{system.profile}', '{system.label.modify_password}');
        return $GLOBALS[RC]->getHelper()->templateResult();
    }

    function changePostAction($oldpassword, $password){
        $model = App::loadModel('account/account', $GLOBALS[RC]->getIdentity()->getId());
        try{
            $model->changePassword($oldpassword, $password);
            $GLOBALS[RC]->getMessager()->addSuccess('{system.message.success}');
        }catch (Core_Component_Account_Exception $ex){
            $GLOBALS[RC]->getMessager()->addError('{account.'.$ex->getMessage().'}');
        }
        return $GLOBALS[RC]->getHelper()->redirectResult();
    }
    
    public function randomAction($id) {
        $model = App::loadModel('account/account', $id);
        $password = $model->randomPassword();
        $GLOBALS[RC]->getHelper()->setLocation('{account.account}', $model->getUserName(), '{account.random_password}');
        return $GLOBALS[RC]->getHelper()->templateResult(array('password' => $password));
    }    
}